﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace SolverOptimizationAPI.Controllers
{
    public class OptimizationInfo2 : OptimizationInfo
    {
        public double Step { get; set; }
    }

    public class FrontierController : ApiController
    {
        OptimizeController optimization = new OptimizeController();

        // POST api/frontier
        public List<OptimizedResults> Post(OptimizationInfo2 info)
        {
            if (info.Step < 0.0001) info.Step = 0.0025;

            OptimizedResults results = null;
            List<OptimizedResults> listResults = new List<OptimizedResults>();
            do
            {
                var newInfo = new OptimizationInfo();
                newInfo.Stocks = info.Stocks;

                if (results == null)
                {
                    newInfo.MinimumReturn = info.MinimumReturn;
                }
                else
                {
                    newInfo.MinimumReturn = listResults.Last().ExpectedReturn + 0.0025;
                }

                
                results = optimization.Post(newInfo);

                if (results.Optimal)
                {
                    listResults.Add(results);
                }

            } while (results.Optimal);

            return listResults;
        }
    }
}
